<template>
  <div class='content'>

    <div class="tables">
      <el-table :data="tableData" stripe style="width: 100%">
        <!-- 设置表头数据源，并循环渲染出来，property对应列内容的字段名 -->
        <el-table-column v-for="info in rightHeader" :key="info.key" :property="info.key" :label="info.label"
                         align="center">
          <template slot-scope="scope">
            <!-- 渲染对应表格里面的内容 -->
            {{ genData(scope)}}
          </template>
        </el-table-column>

        <el-table-column prop="status" key="status" label="状态" width="100" fixed="right" align="center">
          <template slot-scope="scope">

                  <el-tag v-if="scope.row.status==0" type="success">已通过</el-tag>
                  <el-tag v-if="scope.row.status==-1" type="info">未处理</el-tag>
                  <el-tag v-if="scope.row.status>=1" type="danger">{{scope.row.status==1?'已取消':'已驳回'}}</el-tag>

          </template>
        </el-table-column>

        <el-table-column prop="set" label="操作" width="300" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button  type="primary" size="small">修改</el-button>
            <el-button type="danger" @click="centerDialogVisible=true"  size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pages">
      <el-pagination background layout="prev, pager, next" :page-size="10" :total="100"
                     @current-change="handleCurrentChange">
      </el-pagination>
    </div>


    <el-dialog
      title="提示"
      :visible.sync="centerDialogVisible"
      width="20%"
      center>
      <span>确定要删除这个套餐吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {pickingStatusMap} from "@/utils/constant"
  export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      //这里存放数据
      return {
        centerDialogVisible:false,
        serchVal: null,
        inventoryType: null,
        rightHeader: [
          {
            key:'id',
            label:'编号'
          },
          {
            key:'time',
            label:'申请时间'
          },
          {
            key:'name',
            label:"商家"
          },
          {
            key:'content',
            label:'套餐内容'
          },
          {
            key:'totalPrice',
            label:'总价'
          }

        ],
        tableData: [
            {

            time: '2015-10-1 16:00',
            content: [
              {name:"套餐1",count:1},
              {name:"套餐2",count:2}
            ],
            name:"张三", id:'55',
            totalPrice: '￥30.00',
            status:0
          },
          {

            time: '2015-10-1 16:00',
            content: [
              {name:"套餐1",count:1},
              {name:"套餐2",count:2}
            ],
            name:"张三", id:'55',
            totalPrice: '￥30.00',
            status:-1
          },
          {

            time: '2015-10-1 16:00',
            content: [
              {name:"套餐1",count:1},
              {name:"套餐2",count:2}
            ],
            name:"张三", id:'55',
            totalPrice: '￥30.00',
            status:1
          },
          {

            time: '2015-10-1 16:00',
            content: [
              {name:"套餐1",count:1},
              {name:"套餐2",count:2}
            ],
            name:"张三", id:'55',
            totalPrice: '￥30.00',
            status:2
          },
        ]
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      handleClick(e) {
        console.log(e)
      },
      handleCurrentChange(e) {
        console.log(e)
      },
      genData(scope){

        if(scope.column.property=="content") {
          let str =  scope.row[scope.column.property].reduce((total,item,index)=>{
            let str2 = index==scope.row[scope.column.property].length-1?"":" + "
            return total+item.name+"*"+item.count+str2
          },"");
          str = str.length>=30?str.substr(0,30)+"...":str
          return str;
        }
        else
          return scope.row[scope.column.property];
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {

    },
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }

</script>
<style lang='scss' scoped>
  @import '~@/styles/chow.scss';

</style>
